<?php

namespace app\common\cachemodel\consult;

use app\common\model\BaseCache;

class AppUserConsultGiftUseRecord extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.app_user_consult_gift_use_record';

    protected $cacheModel = 'user.voice_consult_gift_use_record';

    /**
     * 新增 用户礼包
     * @param $data
     * @return int
     */
    public function saveData($data)
    {
        try
        {
            $id = $this->insertGetId($data);

            $this->listDataAdd($data['ug_id'], [$id => $id]);
            return (int)$id;
        }
        catch (\Exception $e)
        {
            \think\Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
            return 0;
        }
    }

    /**
     * 开启了缓存
     * @param $ids
     * @param $type
     * @param $sortType
     * @return array|false|string
     */
    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        try
        {
            if ($ids)
            {
                $this->whereIn('id', $ids);
            } else
            {
                $this->where(['ug_id' => $type[0]]);
            }

            $questionResult = $this->order('id ' . $sortType)
                ->column('uid,ug_id as gift_id,use_min,rtc_id,chat_detail_id,create_time,use_time', 'id');
        }
        catch (\Exception $e)
        {
            \think\Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
            return [];
        }

        return $questionResult;
    }
}